﻿import Taro, { Component } from '@tarojs/taro'
import { Swiper, SwiperItem, Image, View, Text } from '@tarojs/components'
import '../../assets/common.scss'
import CommonJs from '../../utils/common'
import './pointsdetails.scss'

import xl from '../../assets/kedouimg01/xl.png'

export default class Index extends Component {
  constructor(props) {
    super(props);
    this.state = {
      resdata:[],
      result:[], 
      pageNumber:0,
      norecords:'',
      money:0,
      islisyr:0,
      createDateEnd:'',
    }
  }
  config = {
    navigationBarTitleText: '加载中'
  }
  componentWillMount () {
    var money =this.$router.preload.money;
      this.setState({
      	money:money
	  })
    this.getCashList(0)
  }
  getCashList(pageNumber){
    var _this=this;
    if(_this.state.createDateEnd != ''){
 	 	var url = '/crm/papi/v1.9/currency?assetType=RMB'+ '&createDateEnd=' + _this.state.createDateEnd
 	   }else{
 	 	var url = '/crm/papi/v1.9/currency?assetType=RMB'
 	 }
    // console.log(JSON.stringify(date1)+'date1')
    CommonJs.ajaxRequest(url,'','GET',function(res){
      // console.log(JSON.stringify(res)+'//33333333333333333')
      Taro.setNavigationBarTitle({title:"收支明细"})
      if (res.data.length>0) {
        _this.state.resdata = res.data[0]
	      var result = res.data[0].assetTypeDetailsList
        var results = _this.state.result
        if(pageNumber==0){
          results=[]
          }
	      for(var i = 0; i < result.length; i++){
	        results.push(result[i]);
	      }
	        _this.setState({
	          result: results,
	        })
	    }      
    },'wfw')
  }
  getTradeName(id){
    var tradeName = ''
    if(id==201){
      tradeName = '充值'
    }
    else if(id==202){
      tradeName = '转账'
    }
    else if(id==203){
      tradeName = '消费'
    }
    else if(id==204){
      tradeName = '提现'
    }
    else if(id==301){
      tradeName = '系统回退'
    }
    else if(id==401){
      tradeName = '返点'
    }
    else if(id==501){
      tradeName = '提现手续费'
    }
    return tradeName
  }
  opendetails(url){
    this.$preload({
      regType:2
    })
    CommonJs.openTo(url)
  }
  open(url){
    CommonJs.openTo(url)
  }
  txfun(){
  	var _this=this;
  	Taro.showActionSheet({
		  itemList:['提现','查看提现记录'],
		  success: function (res) {
		    var tpindex=res.tapIndex;
		    if(tpindex==0){
		    	_this.open('/pages/my/tx?type=BALANCE_RMB')
		    }
		    else if(tpindex==1){
		    	_this.open('/pages/my/txlist')
		    }
		  },
		  fail: function (res) {
		    console.log(res.errMsg)
		  }
		})
  }
  onDateChange(e){
		var _this = this;
	  var createDateEnd = _this.state.createDateEnd
	  var evalue = e.detail.value
		  createDateEnd =evalue
		  _this.setState({
			  result:[],
			  createDateEnd:createDateEnd,
			  islisyr:1
			})
		setTimeout(function(){
			_this.getCashList(0)
		},600)
	}
  render () {
    const result = this.state.result
    const money = this.state.money
    return (
      <View className='page'>
        <ScrollView className='qun-mingxibo' scrollY='true' onScrollToLower={this.loadMore.bind(this,'')}>
          <View className='qun-keyong' style="height:150rpx;">
            <View className='qun-keyong1 qun-keyongs'>可用余额（元）</View>
            <View className='qun-keyong2 qun-keyongs'>{money/100}</View>
  					<View className='qun-keyong1 qun-keyongs' onClick={this.txfun.bind(this)} style="padding:3px 10px;border:1px solid #fff;margin:5px 0;border-radius:10rpx">提现</View>
						<View className='wdt-lis'>
							<Picker mode='date' onChange={this.onDateChange.bind(this)} fields='month'>
                			  <View className='picker'>{this.state.islisyr == 1 ?this.state.createDateEnd : '本月'}<Image className='xl' mode='widthFix' src={xl}></Image></View>
              				</Picker>
					 </View>
            
          </View>
          <View className='qun-mngxi'>收支明细</View>
          {result.length > 0 ?
            result.map((item, index) => (
            <View className='qun-mingxilist'>
              <View className='qun-mngxicont'>
                <View className='qun-mngxileft'>
                  <Text className='qun-minxizngs qun-reanao'>{item.businessId}</Text>
                  <Text className='qun-minxizngs qun-minxitit'>备注:{item.note ? item.note : '无备注'}</Text>
                  <Text className='qun-minxizngs qun-minxitit'>交易类型:{item.behaviorName}</Text>
                </View>
                <View className='qun-mngxiright'>
                  <Text className='qun-minxizngs qun-minxitime'>{CommonJs.FormatDate(item.createAt,3)}</Text>
                  <Text className={item.changeAmount > 0 ? 'qun-minxizngs qun-minxijine' : 'qun-minxizngs qun-minxijine qun-colors'}>{item.changeAmount/100}</Text>
                </View>
              </View>
            </View>
            ))
            :
            <View className='qun-norecords'>{this.state.norecords}</View>
          }
        </ScrollView>
      </View>
    )
  }
}

 